package com.hyg.module_testing.ui.webutil;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Build;
import android.util.Log;
import android.webkit.SafeBrowsingResponse;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * @author: Administrator
 * @date: 2020/12/1
 */
public class MyWebViewClient extends WebViewClient {
    @SuppressWarnings("deprecation")
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
//            if (!urlList.contains(url)) {
//                addWeb(url);
//                urlList.add(url);
////                jugdeWebBack();
//                return true;
//            } else {
        return super.shouldOverrideUrlLoading(view, url);
//            }

    }

    @Override
    public void onReceivedError(WebView view , WebResourceRequest request, WebResourceError error){
        super.onReceivedError(view,request,error);
    }

    @Override
    public void onReceivedSslError(WebView view , SslErrorHandler handler, SslError error){
        //继续加载
        handler.proceed();
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @TargetApi(Build.VERSION_CODES.N)
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        view.loadUrl(request.getUrl().toString());
        return true;
    }

    @Override
    public void onSafeBrowsingHit(WebView view, WebResourceRequest request,
                                  int threatType, SafeBrowsingResponse callback) {
        // The "true" argument indicates that your app reports incidents like
        // this one to Safe Browsing.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
            callback.backToSafety(true);
        }
        //            Toast.makeText(view.getContext(), "Unsafe web page blocked.",
//                    Toast.LENGTH_LONG).show();
    }
}
